package com.gl.saasservice.oss.controller;

import com.gl.framework.web.response.Result;
import com.gl.saasservice.oss.service.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 阿里云OSS对象存储
 * 
 * @author shun
 * @createDate: 2021年3月24日 下午4:48:05
 * @version: 1.0
 *
 */
@Controller
@RequestMapping("/oss")
public class OSSController {
	@Autowired
	private OSSService OSSService;

	/**
	 * 文件上传
	 * 
	 * @param file
	 * @param bucketName
	 * @param type
	 * @return
	 * @author shun
	 * @date 2021年3月24日
	 */
	@PostMapping(value = "/file/{type}")
	@ResponseBody
	public Result putFile(@RequestParam("file") MultipartFile file, String bucketName,
						  @PathVariable String type) {
		return OSSService.putFile(bucketName, file, type);
	}

	/**
	 * 文件删除
	 * 
	 * @param fileKey
	 * @param bucketName
	 * @return
	 * @author shun
	 * @date 2021年3月24日
	 */
	@DeleteMapping(value = "/file")
	@ResponseBody
	public Result deleteObject(@RequestParam(required = true) String fileKey,
			@RequestParam(required = false) String bucketName) {
		return OSSService.deleteObject(bucketName, fileKey);
	}
}
